package l.l.w.leetcode.PalindromeNumber;

/**
 * Created by llw on 2017/8/29.
 */
public class PalindromeNumber {
    public boolean isPalindrome1(int x) {
        if (x<0 || (x!=0 && x%10==0)) return false;
        int[] arr = new int[10];
        x=Math.abs(x);
        int k = 0;
        while(x!=0){
            arr[k++]=x%10;
            x=x/10;
        }
        for(int i=0,j=k-1;i<=j;){
            if(arr[i++]!=arr[j--])
                return false;
        }
        return true;
    }
    public boolean isPalindrome(int x) {
        if(x<0 || x!=0 && x%10==0) return false;
        int reverse=0;
        int temp=x;
        while(temp!= 0){
            reverse = reverse*10+temp%10;
            temp=temp/10;
        }
        if(x==reverse)return true;
        else return false;
    }
    public static void main(String[] args) {
        int a = 1;
        System.out.println(new PalindromeNumber().isPalindrome(a));
    }
}
